# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=sigal
pkgver=2.4
pkgrel=1
pkgdesc="Yet another simple static gallery generator"
arch=(any)
url="http://sigal.saimon.org/en/latest/"
_url="https://github.com/saimn/sigal"
license=(MIT)
depends=(
  ffmpeg
  python
  python-blinker
  python-click
  python-jinja
  python-markdown
  python-natsort
  python-pillow
  python-pilkit
)
makedepends=(
  python-build
  python-installer
  python-setuptools-scm
  python-toml
  python-wheel
)
checkdepends=(
  python-boto
  python-brotli
  python-cryptography
  python-feedgenerator
  python-pytest
  python-zopfli
)
optdepends=(
  'python-boto: upload to S3 plugin'
  'python-brotli: compress assets plugin'
  'python-cryptography: encrypt plugin'
  'python-feedgenerator: feed plugin'
  'python-markupsafe: feed plugin'
  'python-zopfli: compress assets plugin'
)
source=(
  $pkgname-$pkgver.tar.gz::$_url/archive/refs/tags/$pkgver.tar.gz
  $pkgname-2.4-package_data.patch
)
sha512sums=('f561d0d5ea32c3f4616db362957083b5fbd8cea86e1c5d8e0df1d0900eac7132351198356c0f2738b89bcbaa265ef248d72d61ca7f53799001a73b24dfba1671'
            '7a2e503c6fc949c7c963a9f66408322a16ff5ecce73902f9ada7c996f05520e62a61c1e040f8bc2806b482c6023fc2729465da166a132464316c0967d8f766a3')
b2sums=('df9dd2cd56e10c117818d2bc1bc9068b0c6b24f6ea1ec9fabbdce471caac327842c81904a5fee6cfbec29d85b59ff094b211ed1ffad16b50cb9a6fccc4a01bf2'
        '94c5d6e59c9dd43d71c1316971f453f4678e96e9322656cc2eb30077b2dc065b44f7ee707fd99e55124d5838f0a3a9af113f5b24a7e52dfa80d3a3228fafc907')

prepare() {
  # fix issue with data files not being installed: https://github.com/saimn/sigal/issues/500
  patch -Np1 -d $pkgname-$pkgver -i ../$pkgname-2.4-package_data.patch
}

build() {
  cd $pkgname-$pkgver
  SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
  )

  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $pkgname-$pkgver
  # install to temporary location, as importlib is used
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="$PWD/test_dir/$site_packages:$PYTHONPATH"
  pytest "${pytest_options[@]}"
}

package() {
  cd $pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 {AUTHORS,{CONTRIBUTING,README}.rst} -t "$pkgdir/usr/share/doc/$pkgname/"
}
